﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemaIP_cars
{
    class Client
    {
        private string nume;
        private int varsta;
        private List<Masina> listaMasini;
    
        public Client(string n, int v)
        {
            nume = n;
            varsta = v;
            listaMasini=new List<Masina>();

        }

        public void adaugaMasina(Masina m)
        {
            listaMasini.Add(m);
            Console.WriteLine("-> "+nume + " a cumparat masina " + m.getNume());
        }

        public Masina stergeMasina()
        {
            Console.Write("Masina ce trebuie stearsa: ");
            string nm=Console.ReadLine();

            foreach (Masina m in listaMasini)
            {
                if (m.getNume() == nm)
                {
                    listaMasini.Remove(m);

                    Console.WriteLine("-> Masina " + nm + " a fost stearsa de la clientul " + nume);
                    return m;
                }
            }
            Console.WriteLine("-> Clientul " + nume + " nu detine o masina "+ nm);
            return null;
        }

        public void afisareLista()
        {
            if (listaMasini.Count == 0)
            {
                Console.WriteLine("-> "+nume+ " nu detine nicio masina");
                return;
            }
            Console.WriteLine("-> "+nume+" detine urmatoarele masini:");
            foreach (Masina m in listaMasini)
            {
                Console.WriteLine(m.getNume());
            }
        }

        public string getNume() { return nume; }
     }
}
